package com.zzz.gp.service.analyse;

import com.zzz.gp.dao.GpMapper;
import com.zzz.gp.utils.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @description:
 * @author: ZZZ
 * @time: 2022/1/10 12:50
 */
@Slf4j
@Service
public class A17Service {
    @Autowired
    private GpMapper gpMapper;

    @Value("${A17}")
    private String path1;

    @Async("myAsync")
    public void init() {
        DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String today=dtf.format(LocalDateTime.now());
        String path="/home/"+today+path1;
        LocalDateTime s = LocalDateTime.now();
        List<String> list = gpMapper.getA17();

        StringBuilder sb = new StringBuilder("");
        list.forEach(x -> {
            sb.append(",").append(x);
        });
        if (sb.length() > 0) {
            FileUtil.txtWriter(path, sb.substring(1));
        }

        LocalDateTime e = LocalDateTime.now();
        long seconds = Duration.between(s, e).getSeconds();
        log.info("A17分析 用时{}秒,符合数量{}支", seconds, list.size());
        log.info(list.toString());
    }

}
